﻿#ifndef TRKLINEWIDGET_H
#define TRKLINEWIDGET_H

#include <QPen>
#include <QWidget>
#include "TrTypes.h"
#include "TrManager.h"
#include "TrDataManager.h"
#include "WTSSessionInfo.hpp"

class TrKlineWidget : public QWidget
{
    Q_OBJECT
public:
    TrKlineWidget(CTrManager *ptr, QString code, WTSKlinePeriod stype);
    void initStyle();
    QString getCode();
    QString getPeriodName(WTSKlinePeriod stype);
    void drawDebugInfo(bool show = false);
    TrDataManager*              data;
private:
    QString                     m_strCode;
    WTSKlinePeriod              m_KlinePeriod = KP_DAY;
    int                         m_iWidth;
    int                         m_iHeight;
    CTrManager*                 m_pTrManager;
    Contract                    m_Contract;
    Commodity                   m_Commodity;
    double                      m_dHeightLine;
    double                      m_dLowLine;
    double                      m_dPriceRange;
    double                      m_yScale;

    int                         m_iMaxShowCount;
    int                         m_iNowShowCount;
    int                         m_iRightPadding = 70;
    QPen                        PenGreen;
    QPen                        PenRed;
    QPen                        PenGrey;
    QPen                        PenYellow;
    double                      tf(double c);
    double                      js(double c);
    bool                        m_bShowCrosshairs = false;
    QPointF                     m_mousePoint;
    QRect                       R;


protected:
    virtual void paintEvent(QPaintEvent* event) override;
    virtual void wheelEvent(QWheelEvent *event) override;
    virtual void mouseMoveEvent(QMouseEvent* ev) override;
    virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
    void drawKline();
    void drawGrid();
    void drawText();
    void drawLastPrice();
    void drawCrosshairs();
public slots:
    void OnDataUpdated();
};

#endif // TRKLINEWIDGET_H
